package com.example.mapper;

import Resume.Dto.Resume;
import Resume.Dto.ResumeJobMap;
import org.apache.ibatis.annotations.*;
import pojo.Kmoji;

import java.util.List;

@Mapper
public interface ResumeMapper {
    @Update("update user_resume_company_deliver set status=#{status} where resume_id=#{resumeId}")
    void auditResume(@Param("resumeId") int resumeId, @Param("status") int status);
    @Select("select * from resumes where id=#{id}")
    Resume getResumeById(@Param("id") int id);

    @Select("select * from resumes")
    List<Resume> getResumes();

    @Select("select * from resumes where name =#{name}")
    List<Resume> getResumesByName(String name);

    @Select("select resume_id from resume_user where user_id=#{user_id}")
    List<Integer>  getResumeIdByUserId(int user_id);

    @Select("select * from user_resume_company_deliver where user_id=#{user_id} and status = #{status}")
    List<Integer> getResumeIdByUserIdAndStatus(@Param("user_id") int user_id,@Param("status")int status);

    @Delete("delete from resumes where id = #{id}")
    void deleteResume(@Param("id") int id);

    @Insert("insert into resumes (name,gender,age," +
            "picture,phone_number,email,intention," +
            "abilities,background,experience,resume_url) " +
            "values(#{name},#{gender},#{age},#{picture},#{phoneNumber},#{email},#{intention},#{abilities},#{background},#{experience},#{resumeUrl}) ")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertResume(Resume resume);




    @Update("update resumes set resume_url =#{resume_url} where id =#{resume_id}")
    boolean updateResumeUrl(@Param("resume_id") int resume_id,@Param("resume_url") String resume_url);

    @Update("update resumes " +
            "set id = #{id}, " +
            "name = #{name}, " +
            "gender = #{gender}, " +
            "age = #{age}, " +
            "picture = #{picture}, " +
            "phone_number = #{phoneNumber}, " +
            "email = #{email}, " +
            "intention = #{intention}, " +
            "abilities = #{abilities}, " +
            "background = #{background}, " +
            "experience = #{experience}, " +
            "resume_url = #{resumeUrl} "+
            "where id = #{id}")
    int updateResume( Resume resume);


    @Select("select * from user_resume_company_deliver where company_id=#{companyId} and status=#{status}")
    List<ResumeJobMap> getResumeJobMapByCompanyId(@Param("companyId") int companyId,@Param("status") int status);

    @Select("select * from user_resume_company_deliver where user_id=#{userId} and status=#{status}")
    List<ResumeJobMap> getResumeJobMapByUserId(@Param("userId") int userId,@Param("status") int status);


    @Select("select * from user_resume_company_deliver where company_id=#{companyId}")
    List<ResumeJobMap> getResumeJobMapByCompanyIdAll(@Param("companyId") int companyId);

    @Select("select * from user_resume_company_deliver")
    List<ResumeJobMap> getResumeJobMapAll();

    @Insert("insert into user_resume_company_deliver(user_id, resume_id, company_id, job_id, deliver_time) " +
            "values(#{userId}, #{resumeId}, #{companyId}, #{jobId}, NOW())")
    void submitJob(Kmoji kmoji);

    @Insert("insert into resume_user(resume_id,user_id) values(#{resumeId},#{userId})")
    void addResumeUser(@Param("resumeId") int resumeId,@Param("userId") int userId);
}
